﻿#include "ScalarBarSettingData.h"
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    ScalarBarSettingData::ScalarBarSettingData(QObject* parent)
        : QObject(parent)
    {
    }

    void ScalarBarSettingData::setScalarBarFontSize(int fontSize)
    {
        m_fontSize = fontSize;
    }

    int ScalarBarSettingData::getScalarBarFontSize() const
    {
        return m_fontSize;
    }

    void ScalarBarSettingData::setScalarBarMaxValue(double maxValue)
    {
        m_maxValue = maxValue;
    }

    double ScalarBarSettingData::getScalarBarMaxValue() const
    {
        return m_maxValue;
    }

    void ScalarBarSettingData::setScalarBarMinValue(double minValue)
    {
        m_minValue = minValue;
    }

    double ScalarBarSettingData::getScalarBarMinValue() const
    {
        return m_minValue;
    }

    void ScalarBarSettingData::setScalarBarAutoRange(bool isAutoRange)
    {
        m_isUseScalarBarAutoRange = isAutoRange;
    }

    bool ScalarBarSettingData::getScalarBarAutoRange() const
    {
        return m_isUseScalarBarAutoRange;
    }

    void ScalarBarSettingData::setScalarBarIsShowTitle(bool isShowTitle)
    {
        m_isShowTitle = isShowTitle;
    }

    bool ScalarBarSettingData::getScalarBarIsShowTitle() const
    {
        return m_isShowTitle;
    }

    void ScalarBarSettingData::setScalarBarTitleColor(QColor titleColor)
    {
        m_titleColor = titleColor;
    }

    QColor ScalarBarSettingData::getScalarBarTitleColor() const
    {
        return m_titleColor;
    }

    void ScalarBarSettingData::setScalarBarFontFamily(QString fontFamily)
    {
        m_fontFamily = fontFamily;
    }

    QString ScalarBarSettingData::getScalarBarFontFamily() const
    {
        return m_fontFamily;
    }

    void ScalarBarSettingData::setScalarBarTitle(QString title)
    {
        m_title = title;
    }

    QString ScalarBarSettingData::getScalarBarTitle() const
    {
        return m_title;
    }

    void ScalarBarSettingData::setScalarBarOriginalMinRange(double minValue)
    {
        m_scalarBarMinValueOriginal = minValue;
    }

    double ScalarBarSettingData::getScalarBarOriginalMinRange() const
    {
        return m_scalarBarMinValueOriginal;
    }

    void ScalarBarSettingData::setScalarBarOriginalMaxRange(double maxValue)
    {
        m_scalarBarMaxValueOriginal = maxValue;
    }

    double ScalarBarSettingData::getScalarBarOriginalMaxRange() const
    {
        return m_scalarBarMaxValueOriginal;
    }

    void ScalarBarSettingData::setScalarBarIsLog(bool isLog)
    {
        m_isLog = isLog;
    }

    bool ScalarBarSettingData::getScalarBarIsLog() const
    {
        return m_isLog;
    }

    void ScalarBarSettingData::setScalarBarUnit(QString unit)
    {
        m_unit = unit;
    }

    QString ScalarBarSettingData::getScalarBarUnit() const
    {
        return m_unit;
    }

    QDomElement& ScalarBarSettingData::writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso)
    {
        QDomElement _ScalarBarSettingDataRoot = doc->createElement("ScalarBarSettingData");

        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "FontSize", QString::number(m_fontSize));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "MaxValue", QString::number(m_maxValue));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "MinValue", QString::number(m_minValue));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "IsUseScalarBarAutoRange", QString::number(m_isUseScalarBarAutoRange));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "IsShowTitle", QString::number(m_isShowTitle));
        QString _TitleColorstr = QString("%1,%2,%3").arg(m_titleColor.red()).arg(m_titleColor.green()).arg(m_titleColor.blue());
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "TitleColor", _TitleColorstr);
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "FontFamily", m_fontFamily);
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "Title", m_title);
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "IsLog", QString::number(m_isLog));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "Unit", m_unit);
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "ScalarBarMinValueOriginal", QString::number(m_scalarBarMinValueOriginal));
        GlobalHelperInstance->createDomElement(doc, &_ScalarBarSettingDataRoot, "ScalarBarMaxValueOriginal", QString::number(m_scalarBarMaxValueOriginal));

        element->appendChild(_ScalarBarSettingDataRoot);

        return _ScalarBarSettingDataRoot;
    }

    void ScalarBarSettingData::readFromProjectFile(QDomElement* element, bool isdiso)
    {
        auto _FontSizeNodeList = element->elementsByTagName("FontSize");
        m_fontSize = _FontSizeNodeList.item(0).toElement().text().toInt();
        auto _MaxValueNodeList = element->elementsByTagName("MaxValue");
        m_maxValue = _MaxValueNodeList.item(0).toElement().text().toDouble();
        auto _MinValueNodeList = element->elementsByTagName("MinValue");
        m_minValue = _MinValueNodeList.item(0).toElement().text().toDouble();
        auto _IsUseScalarBarAutoRangeNodeList = element->elementsByTagName("IsUseScalarBarAutoRange");
        m_isUseScalarBarAutoRange = (bool)_IsUseScalarBarAutoRangeNodeList.item(0).toElement().text().toInt();
        auto _IsShowTitleNodeList = element->elementsByTagName("IsShowTitle");
        m_isShowTitle = (bool)_IsShowTitleNodeList.item(0).toElement().text().toInt();
        auto _TitleColorNodeList = element->elementsByTagName("TitleColor");
        auto _TitleColorStr = _TitleColorNodeList.item(0).toElement().text();
        auto _TitleColorRGB = _TitleColorStr.split(",");
        m_titleColor.setRgb(_TitleColorRGB.at(0).toDouble(), _TitleColorRGB.at(1).toDouble(), _TitleColorRGB.at(2).toDouble());
        auto _FontFamilyNodeList = element->elementsByTagName("FontFamily");
        m_fontFamily = _FontFamilyNodeList.item(0).toElement().text();
        auto _TitleNodeList = element->elementsByTagName("Title");
        m_title = _TitleNodeList.item(0).toElement().text();
        auto _IsLogNodeList = element->elementsByTagName("IsLog");
        m_isLog = _IsLogNodeList.item(0).toElement().text().toInt();
        auto _UnitNodeList = element->elementsByTagName("Unit");
        m_unit = _UnitNodeList.item(0).toElement().text();
        auto _ScalarBarMinValueOriginalNodeList = element->elementsByTagName("ScalarBarMinValueOriginal");
        m_scalarBarMinValueOriginal = _ScalarBarMinValueOriginalNodeList.item(0).toElement().text().toDouble();
        auto _ScalarBarMaxValueOriginalNodeList = element->elementsByTagName("ScalarBarMaxValueOriginal");
        m_scalarBarMaxValueOriginal = _ScalarBarMaxValueOriginalNodeList.item(0).toElement().text().toDouble();
    }

}
